package com.rocksdata.mc.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ctz.commonframe.ui.TitleBarActivity;
import com.rocksdata.mc.business.BusinessManager;
import com.rocksdata.mc.entity.StudentInfo;
import com.rocksdata.mc.entity.TeacherInfo;
import com.rocksdata.mc.Constant;
import com.rocksdata.mc.R;
import com.rocksdata.mc.business.UserInfoManager;
import com.rocksdata.mc.entity.UserInfo;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

/**
 * Created by 陈堂正 on 2017/4/6.
 */
@ContentView(R.layout.activity_user_info)
public class UserInfoActivity extends TitleBarActivity {
    @ViewInject(R.id.iv_head)
    private ImageView ivHead;
    @ViewInject(R.id.tv_name)
    private TextView tvName;
    @ViewInject(R.id.tv_belong_to)
    private TextView tvBelongto;
    @ViewInject(R.id.tv_belong_to_label)
    private TextView tvBelongTolabel;
    @ViewInject(R.id.tv_id)
    private TextView tvId;
    @ViewInject(R.id.tv_id_label)
    private TextView tvIdlabel;

    private UserInfo userInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        userInfo = (UserInfo) getIntent().getSerializableExtra(Constant.EXTRA_KEY_USER_INFO);
        setTitleMiddleText("个人信息");
//        XUtils3ImageDisplayer.display(ivHead, userInfo.getHeadUrl());
        tvName.setText(UserInfoManager.getCurrentName());
        String parentName = "";
        switch (UserInfoManager.getCurrentUserType()){
            case UserInfoManager.USER_TYPE_STUDENT:
                tvBelongTolabel.setText("班级");
                tvIdlabel.setText("学号");
                userInfo = BusinessManager.getUserInfoManager().getStudentInfoLocal(UserInfoManager.getCurrentUserId());
                parentName = ((StudentInfo)userInfo).getStudentClass().getClassName();
                break;
            case UserInfoManager.USER_TYPE_TEACHER:
                tvBelongTolabel.setText("部门");
                tvIdlabel.setText("工号");
                userInfo = BusinessManager.getUserInfoManager().getTeacherInfoLocal(UserInfoManager.getCurrentUserId());
                parentName = ((TeacherInfo)userInfo).getDepartment().getDepartmentName();

                break;
        }
        tvBelongto.setText(parentName);

        tvId.setText(UserInfoManager.getCurrentUserId());
    }

    @Event(value = {R.id.layout_qrcode}, type = View.OnClickListener.class)
    private void OnClick(View v) {
        switch (v.getId()){
            case R.id.layout_qrcode:
                startActivity(new Intent(UserInfoActivity.this, QRCodeActivity.class).putExtra(Constant.EXTRA_KEY_USER_INFO, userInfo));
                break;
        }
    }
}
